package com.ymatou.iapi.couponmanage.testcase;

import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.couponmanage.parameter.CreateBagBean;
import com.ymatou.iapi.couponmanage.parameter.CreateBean;
import com.ymatou.iapi.couponmanage.parameter.CreateCouponBean;
import com.ymatou.iapi.couponmanage.parameter.GetIdByBatchBean;
import com.ymatou.iapi.couponmanage.service.CreateBagCall;
import com.ymatou.iapi.couponmanage.service.CreateCouponCall;
import com.ymatou.iapi.couponmanage.service.GetIdByBatchCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CouponServiceMCallServiceV2;
import com.ymttest.database.model.couponconversion;
import com.ymttest.database.model.couponconversionbatch;
import com.ymttest.database.sqlwapper.couponconversionWapper;
import com.ymttest.database.sqlwapper.couponconversionbatchWapper;
//import com.ymttest.database.model.couponconversionbatch;
//import com.ymttest.database.model.couponconversion;
//import com.ymttest.database.sqlwapper.couponconversionbatchWapper;
//import com.ymttest.database.sqlwapper.couponconversionWapper;
/**
*通过优惠券批次获取兑换码单据Id
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetIdByBatch{
	private static GetIdByBatchBean getidbybatchBean;
	private static GetIdByBatchCall getidbybatchCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("通过优惠券批次获取兑换码单据Id");
	}

	@Before
	public void caseUp() {
		getidbybatchBean=new GetIdByBatchBean();
		getidbybatchCall=new GetIdByBatchCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getidbybatchCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetIdByBatch_001() {
		Logger.start(true,"通过优惠券批次获取兑换码单据Id");
		try {
			couponconversion bill = new couponconversionWapper().getTop1();
			couponconversionbatch relation = new couponconversionbatchWapper().selectByConversionId(bill.getConversionId()).get(0);
			getidbybatchBean.setBatchCode(relation.getBatchCode());
			
			getidbybatchCall.setData(getidbybatchBean);
			getidbybatchCall.callService();	
			
			Logger.verifyEquals("0", getidbybatchCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getidbybatchCall.getMessage(), "验证返回Message");

			String conversionBillId = getidbybatchCall.getconversionBillId();
			Logger.verifyEquals(bill.getConversionId(), Integer.parseInt(conversionBillId), "验证返回conversionBillId");
	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetIdByBatch_002() {
		Logger.start(true,"通过优惠券批次获取兑换码单据Id-BatchCode空");
		try {

			getidbybatchCall.setData(getidbybatchBean);
			getidbybatchCall.callService();	
			
//			Logger.verifyEquals("2", getidbybatchCall.getCode(), "验证返回code");
			Logger.verifyIsContains("batchCode:batchCode must not be blank", getidbybatchCall.getMessage(), "验证返回Message");
	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetIdByBatch_003() {
		Logger.start(true,"通过优惠券批次获取兑换码单据Id-BatchCode不存在");
		try {

			getidbybatchBean.setBatchCode("9999999");
			
			getidbybatchCall.setData(getidbybatchBean);
			getidbybatchCall.callService();	
			
			Logger.verifyEquals("0", getidbybatchCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getidbybatchCall.getMessage(), "验证返回Message");

			String conversionBillId = getidbybatchCall.getconversionBillId();
			Logger.verifyEquals(0, Integer.parseInt(conversionBillId), "验证无返回conversionBillId");
	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetIdByBatch_004() {
		Logger.start(true,"通过优惠券批次获取兑换码单据Id-套券");
		try {

			CouponServiceMCallServiceV2 couponCallService = new CouponServiceMCallServiceV2();
			CreateBagBean createBagBean = couponCallService.setDefaultPlatformCreateCouponBagBeanForRecieve();
			createBagBean.setAcquireMethod(2);
			
			CreateBagCall createBagCall = couponCallService.createPlatformCouponBag(createBagBean);
			List<String> batchCodes= new ArrayList<>();
			batchCodes.add(createBagCall.getbagCode());
			CreateBean CreateBean=couponCallService.setDefaultRandomCreateBean(batchCodes);
			CreateBean.setBatchType(2);
			couponCallService.create(CreateBean);
			
			couponconversion bill = new couponconversionWapper().getTop1();
			couponconversionbatch relation = new couponconversionbatchWapper().selectByConversionId(bill.getConversionId()).get(0);
			
			getidbybatchBean.setBatchCode(relation.getBatchCode());
			
			getidbybatchCall.setData(getidbybatchBean);
			getidbybatchCall.callService();	
			
			Logger.verifyEquals("0", getidbybatchCall.getCode(), "验证返回code");
			Logger.verifyEquals("操作成功！", getidbybatchCall.getMessage(), "验证返回Message");

			String conversionBillId = getidbybatchCall.getconversionBillId();
			Logger.verifyEquals(bill.getConversionId(), Integer.parseInt(conversionBillId), "验证返回conversionBillId");
	
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}